package org.example;

import java.util.ArrayDeque;
import java.util.Arrays;
import java.util.Deque;

public class Test2 {
    //leetcode 503 下一个更大元素II https://leetcode.cn/problems/next-greater-element-i/description/
    public int[] nextGreaterElements(int[] nums) {
        int n = nums.length;
        int[] ret = new int[n];
        Arrays.fill(ret,-1);
        Deque<Integer> deque = new ArrayDeque<>();
        deque.add(0);
        for (int i = 1; i < n*2; i++) {
            while (!deque.isEmpty() && nums[i%n] > nums[deque.peekFirst()%n]) {
                ret[deque.removeFirst()%n] = nums[i%n];
            }
            deque.addFirst(i);
        }
        return ret;
    }

    public static void main(String[] args) {
        Test2 test2 = new Test2();
        int[] nums = {1,2,1};
        test2.nextGreaterElements(nums);
        System.out.println(444);
    }
}
